Skip to content

fix(i18n): reject invalid input in ind_pan and fr_ssn - #469

Closed
Jordan-Bourillot wants to merge 2 commits into
python-validators:masterfrom
Jordan-Bourillot:fix/i18n-validator-regexes
Closed

Jordan-Bourillot wants to merge 2 commits into
python-validators:masterfrom
Jordan-Bourillot:fix/i18n-validator-regexes

Conversation

@Jordan-Bourillot

Copy link
Copy Markdown
Contributor

Two small regex-correctness fixes in the i18n validators; each currently lets invalid input through. Both are covered by new regression tests that fail on master and pass with this change. ruff is clean and the full suite passes.

ind_pan — trailing characters accepted

ind_pan used re.match(r"[A-Z]{5}\d{4}[A-Z]{1}", value) with no trailing $. re.match only anchors the start, so any string that begins with a valid PAN was accepted:

>>> validators.ind_pan('ABCDE9999KEXTRA')   # truthy -> "valid", should be invalid

Anchored the pattern with ^…$, matching the ind_aadhar pattern just above it.

fr_ssn — comma accepted as gender / Corsica suffix

The SSN regex used the character classes [1,2] and 2[A,B], which also match a literal comma:

>>> validators.fr_ssn(', 84 12 76 451 089')
True   # should be invalid

Dropped the commas ([12] and [AB]). Valid SSNs are unaffected.

The SSN regex used the character classes [1,2] and 2[A,B], which also
match a literal comma. fr_ssn(', 84 12 76 451 089') was therefore
accepted as valid. Drop the commas ([12] and [AB]); valid SSNs are
unaffected.
ind_pan used re.match(r"[A-Z]{5}\d{4}[A-Z]{1}", ...) with no trailing $,
so any string starting with a valid PAN was accepted -- e.g.
ind_pan('ABCDE9999KEXTRA') returned a match. Anchor the pattern with
^...$, matching the ind_aadhar style just above it.
@nandgator

Copy link
Copy Markdown
Collaborator

Thank you for the contribution! The Indian PAN anchoring already landed through #478, and the fr_ssn comma fix is now on master via #491 (your commit, authorship preserved). Closing as covered.

@nandgator nandgator closed this Oct 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants